const db = require('../db');
const { hashPassword } = require('../utils/passwordUtils');

async function createAdmin() {
    try {
        // 生成加密密码
        const password = '123456';
        const hashedPassword = await hashPassword(password);
        
        // 先删除已存在的 admin 账号
        await db.promise().execute('DELETE FROM admin WHERE username = ?', ['admin']);
        
        // 创建新的管理员账号
        const [result] = await db.promise().execute(
            'INSERT INTO admin (username, password, nickname, status) VALUES (?, ?, ?, ?)',
            ['admin', hashedPassword, '系统管理员', 1]
        );
        
        console.log('管理员账号创建成功');
        console.log('用户名: admin');
        console.log('密码: 123456');
        console.log('密码哈希:', hashedPassword);
        process.exit(0);
    } catch (error) {
        console.error('创建管理员账号失败:', error);
        process.exit(1);
    }
}

createAdmin(); 